using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_AV95RULES
    {
        public void MapICC_AV95RULES(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_AV95RULES(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryICC_AV95RULES(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapICC_AV95RULES(ref dwLocal, dwData);

            if (!flgExist)
            {
                dwLocal["ROWNID"] =INTEXDBC.GetSeq();
                InsertICC_AV95RULES(dwLocal, ITXDBVERSION);
            }
            UpdateICC_AV95RULES(dwLocal);
        }
        public void InsertICC_AV95RULES(DataRow dwData, string ITXDBVERSION = "50.24")
        { 
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "50.24":
                default:
                    or1.CommandText = "INSERT INTO ICC_AV95RULES(ROWNID, PLANID,RGROUP, RULEID, WMIN,WMAX,YARNTYP,WASTAGE,REMARK)"
                                + " VALUES (:ROWNID, :PLANID,:RGROUP, :RULEID, :WMIN,:WMAX,:YARNTYP,:WASTAGE,:REMARK)";
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    or1.Parameters.Add("PLANID", OracleType.NVarChar).Value = dwData["PLANID"].ToString();
                    or1.Parameters.Add("RGROUP", OracleType.NVarChar).Value = dwData["RGROUP"].ToString();
                    or1.Parameters.Add("RULEID", OracleType.NVarChar).Value = dwData["RULEID"].ToString();
                    or1.Parameters.Add("WMIN", OracleType.NVarChar).Value = dwData["WMIN"].ToString();
                    or1.Parameters.Add("WMAX", OracleType.NVarChar).Value = dwData["WMAX"].ToString();
                    or1.Parameters.Add("YARNTYP", OracleType.NVarChar).Value = dwData["YARNTYP"].ToString();
                    or1.Parameters.Add("WASTAGE", OracleType.NVarChar).Value = dwData["WASTAGE"].ToString();
                    or1.Parameters.Add("REMARK", OracleType.NVarChar).Value = dwData["REMARK"].ToString();
                    break; 
            }
            Connect2Proxy(or1);
        } 
        public DataSet QueryICC_AV95RULES(DataRow dwData, int option = 1)
        {
            
            DataSet Result;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = " SELECT * FROM ICC_AV95RULES WHERE   ROWNID=:ROWNID"; ;
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    break;
                case 9999:
                    or1.CommandText = " SELECT * FROM ICC_AV95RULES";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_AV95RULES"; 
            return Result;
        }
        public void UpdateICC_AV95RULES(DataRow dwData, int options = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (options)
            {
                case 1:
                    #region====Command====
                    or1.CommandText = "UPDATE ICC_AV95RULES SET  "
                        + "PLANID=:PLANID,"
                        + "RGROUP=:RGROUP,"
                        + "RULEID=:RULEID,"
                        + "WMIN=:WMIN,"
                        + "WMAX=:WMAX,"
                        + "YARNTYP=:YARNTYP,"
                        + "WASTAGE=:WASTAGE,"
                        + "REMARK=:REMARK "
                        + " WHERE  "
                        + "   ROWNID=:ROWNID ";
                    #endregion
                    #region====Parameters====
                    or1.Parameters.Add("PLANID", OracleType.NVarChar).Value = dwData["PLANID"].ToString();
                    or1.Parameters.Add("RGROUP", OracleType.NVarChar).Value = dwData["RGROUP"].ToString();
                    or1.Parameters.Add("RULEID", OracleType.NVarChar).Value = dwData["RULEID"].ToString();
                    or1.Parameters.Add("WMIN", OracleType.NVarChar).Value = dwData["WMIN"].ToString();
                    or1.Parameters.Add("WMAX", OracleType.NVarChar).Value = dwData["WMAX"].ToString();
                    or1.Parameters.Add("YARNTYP", OracleType.NVarChar).Value = dwData["YARNTYP"].ToString();
                    or1.Parameters.Add("WASTAGE", OracleType.NVarChar).Value = dwData["WASTAGE"].ToString();
                    or1.Parameters.Add("REMARK", OracleType.NVarChar).Value = dwData["REMARK"].ToString();
                    #endregion
                    break;
            }

            Connect2Proxy(or1);
        }
    }
}
